]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - Super Polarity/Actors/Actor.cs
I think bullets come out now.
[rbdr/super-polarity] / Super Polarity / Actors / Actor.cs
index 4351bf22dd71c4b43ad256347135317dc1a7f61b..588ff1421875dcf45c45055afeed61b3c0eb432f 100644 (file)
@@ -12,6 +12,8 @@ namespace SuperPolarity
     {
         protected Game game;
 
+        public List<Actor> Children;
+
         // Graphics / In-Game
         protected Texture2D Texture;
         protected Vector2 Origin;
@@ -21,7 +23,7 @@ namespace SuperPolarity
         public Vector2 Position;
         protected Vector2 Velocity;
         protected Vector2 Acceleration;
-        protected float Angle;
+        public float Angle;
 
         // Constraints / Behavior
         protected float MaxVelocity;
@@ -48,6 +50,8 @@ namespace SuperPolarity
             Position = position;
             Active = true;
 
+            Children = new List<Actor>();
+
             Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
             Velocity = new Vector2(0, 0);
             Acceleration = new Vector2(0, 0);
@@ -115,12 +119,15 @@ namespace SuperPolarity
         {
             Move(gameTime);
             ChangeAngle();
+            CheckOutliers();
         }
 
-        public void Move(GameTime gameTime)
+        public virtual void Move(GameTime gameTime)
         {
             AutoDeccelerate(gameTime);
 
+            var maxVelocity = MaxVelocity;
+
             Velocity.X = Velocity.X + Acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
             Velocity.Y = Velocity.Y + Acceleration.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
 
@@ -155,7 +162,26 @@ namespace SuperPolarity
 
         public virtual void Draw(SpriteBatch spriteBatch)
         {
+            foreach (Actor child in Children)
+            {
+                child.Draw(spriteBatch);
+            }
+
             spriteBatch.Draw(Texture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f);
         }
+
+        void CheckOutliers()
+        {
+            for (var i = Children.Count; i > 0; i--)
+            {
+                var actor = Children[i - 1];
+                if (actor.Position.X < -SuperPolarity.OutlierBounds || actor.Position.Y < -SuperPolarity.OutlierBounds ||
+                    actor.Position.X > game.GraphicsDevice.Viewport.Width + SuperPolarity.OutlierBounds ||
+                    actor.Position.Y > game.GraphicsDevice.Viewport.Height + SuperPolarity.OutlierBounds)
+                {
+                    Children.Remove(actor);
+                }
+            }
+        }
     }
 }